package com.diy.sigmund.diycommon.util.thread;

/**
 * @author ylm-sigmund
 * @since 2023/1/29 10:03
 */
public class TSynchronized implements Runnable{

    static int i = 0;

    public  void increase(){
        i++;
        // ++i;
    }


    @Override
    public void run() {
        for(int i = 0;i < 100000;i++) {
            increase();
        }
    }

    public static void main(String[] args) throws InterruptedException {

        TSynchronized tSynchronized = new TSynchronized();
        Thread aThread = new Thread(tSynchronized);
        Thread bThread = new Thread(tSynchronized);
        aThread.start();
        bThread.start();
        // 使aThread运行结束,等待线程死亡
        aThread.join();
        bThread.join();
        System.out.println("i = " + i);
    }
}

